package com.example.designsoft.base;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.example.designsoft.util.GetClassUtils;

/**
 * author : Gyk
 * time   : 2020/11/17
 * todo   :
 */
public abstract class BaseMvpActivity<T extends BasePresenter, M extends BaseModel> extends Activity {

    public T mPresenter;
    public M mModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        //内部获取第一个类型参数的真实类型  ，反射new出对象
        mPresenter = GetClassUtils.getT(this, 0);
        //内部获取第二个类型参数的真实类型  ，反射new出对象
        mModel = GetClassUtils.getT(this, 1);
        //Presenter层绑定View层与Model层,持有View与Model对象
        mPresenter.attachModelView(mModel, this);
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.onDettach();
    }

    public abstract void initData();
    public abstract int getLayoutResId();
}
